package com.ykg.controller;

import com.ykg.annotation.PassToken;
import com.ykg.enums.ResultEnum;
import com.ykg.interceptor.ScopeLevel;
import com.ykg.pojo.Goods;
import com.ykg.request.ChangePriceRequest;
import com.ykg.service.IGoodsService;
import com.ykg.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * TODO
 * 类(接口)：
 * Created on 20:30 2021/6/24.
 *
 * @Author: laobian
 * @Description:
 */
@Api(tags = "业务部Api")
@RestController
@RequestMapping("/api/goods")
public class GoodsController {
    @Autowired
    private IGoodsService goodsService;

    //@PassToken
    @ApiOperation("获取货品价格")
    @GetMapping(value = "/price",produces = "application/json")
    @ScopeLevel(value = 1)
    public ResultResponse getGoods(){
        Goods goods = goodsService.getGoodsPrice();
        return new ResultResponse(goods);
    }

    //@PassToken
    @ApiOperation("修改货物价格")
    @PostMapping(value = "/changePrice")
    @ScopeLevel(value = 1)
    public ResultResponse changePrice(@RequestBody ChangePriceRequest changePriceRequest){
        if(Objects.isNull(changePriceRequest)){
            return new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        int status = goodsService.changePrice(changePriceRequest);
        if(status == 0){
            return new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(ResultEnum.SUCCESS);

    }
}
